#pragma once
#include "c3d.h"
#include "c3dVertex.h"
#include <cmath>
class c3dSurface
{
public:
	int vIdx[4];
	int vNum = 4;
	vec4 clr;
};
class c3dCube
{
public:
	enum SurfId : int
	{
		TOP = 0,
		BOTTOM = 1,
		LEFT = 2,
		RIGHT = 3,
		FRONT = 4,
		BACK = 5
	};
	c3dCube() {
		data[0].pos = vec4(1, 1, 1, 1); data[0].texcoord = vec4(0, 0, 0, 0);
		data[1].pos = vec4(1, -1, 1, 1); data[1].texcoord = vec4(0, 1, 0, 0);
		data[2].pos = vec4(1, -1, -1, 1); data[2].texcoord = vec4(1, 1, 0, 0);
		data[3].pos = vec4(1, 1, -1, 1); data[3].texcoord = vec4(1, 0, 0, 0);

		data[4].pos = vec4(-1, 1, 1, 1); data[4].texcoord = vec4(0, 0, 0, 0);
		data[5].pos = vec4(-1, -1, 1, 1); data[5].texcoord = vec4(1, 0, 0, 0);
		data[6].pos = vec4(-1, -1, -1, 1); data[6].texcoord = vec4(1, 1, 0, 0);
		data[7].pos = vec4(-1, 1, -1, 1); data[7].texcoord = vec4(1, 0, 0, 0);
		
		for (int i = 0; i < 8; i++)
		{
			int r = rand() % 255; //data[i].pos.x * 128 + 48+i*80;
			int g = rand() % 255; //data[i].pos.y * 128 + 48 + i * 80;
			int b = rand() % 255; //data[i].pos.z * 128 + 48 + i * 80;
			data[i].color = vec4(r, g, b, 1);

		}



		int nCurIdx = TOP;
		surf[nCurIdx].vIdx[0] = 7;
		surf[nCurIdx].vIdx[1] = 4;
		surf[nCurIdx].vIdx[2] = 0;
		surf[nCurIdx].vIdx[3] = 3;
		surf[nCurIdx].clr = vec4(255,0,0,0);
		nCurIdx = BOTTOM;
		surf[nCurIdx].vIdx[0] = 5;
		surf[nCurIdx].vIdx[1] = 6;
		surf[nCurIdx].vIdx[2] = 2;
		surf[nCurIdx].vIdx[3] = 1;
		surf[nCurIdx].clr = vec4(255, 0, 0, 0);
		nCurIdx = LEFT;
		surf[nCurIdx].vIdx[0] = 4;
		surf[nCurIdx].vIdx[1] = 7;
		surf[nCurIdx].vIdx[2] = 6;
		surf[nCurIdx].vIdx[3] = 5;
		surf[nCurIdx].clr = vec4(0, 255, 0, 0);
		nCurIdx = RIGHT;
		surf[nCurIdx].vIdx[0] = 0;
		surf[nCurIdx].vIdx[1] = 1;
		surf[nCurIdx].vIdx[2] = 2;
		surf[nCurIdx].vIdx[3] = 3;
		surf[nCurIdx].clr = vec4(0, 255, 0, 0);

		nCurIdx = FRONT;
		surf[nCurIdx].vIdx[0] = 4;
		surf[nCurIdx].vIdx[1] = 5;
		surf[nCurIdx].vIdx[2] = 1;
		surf[nCurIdx].vIdx[3] = 0;
		surf[nCurIdx].clr = vec4(0, 255, 255, 0);
		nCurIdx = BACK;
		surf[nCurIdx].vIdx[0] = 6;
		surf[nCurIdx].vIdx[1] = 7;
		surf[nCurIdx].vIdx[2] = 3;
		surf[nCurIdx].vIdx[3] = 2;
		surf[nCurIdx].clr = vec4(0, 0, 255, 0);
		//for (int i = 0; i < 8; ++i)
		//{
		//	data[i].pos.x += 1;
		//	data[i].pos.y += 1;
		//	data[i].pos.z += 1;
		//	//data[i].pos.w = f;
		//}
		SetScale(80);
	}
	bool SetScale(float f)
	{
		if (f == 0)
		{
			return false;
		}
		for (int i = 0; i < 8; ++i)
		{
			data[i].pos.x *= f;
			data[i].pos.y *= f;
			data[i].pos.z *= f;
			//data[i].pos.w = f;
		}
		return true;
	};



	c3dSurface surf[6];
	c3dVertex data[8];

	//vec4 data[8];
};